package com.qf.qfcenterdata.service;

import com.qf.common.constant.RedisConstant;
import com.qf.common.model.DeviceModelValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class RedisService {

    @Autowired
    private StringRedisTemplate redisTemplate;

    public void saveDeviceState(DeviceModelValue deviceModelValue){
        String key = RedisConstant.DEVICE_ONLINE_KEY_PREFIX + deviceModelValue.getProduct_key() + "-" +deviceModelValue.getDevice();
        String value = "";
        long time = RedisConstant.DEVICE_ONLINE_TIMEOUT;
        TimeUnit unit = RedisConstant.DEVICE_TIME_UNIT;
        redisTemplate.opsForValue().set(key,value,time,unit);
    }
}
